<template>
    <Layout>
        <Form ref="form1" :model="form1" :label-width="120">
            <Row class="query-form" style="padding-top: 10px" v-show="!switchFlag">
                <Col span="8">
                    <FormItem label="风险类别：">
                        <Select filterable v-model="form1.riskType"
                                :label-in-value="true">
                            <Option v-for="item in riskTypeArr" :value="item.codingCodeId" :label="item.codingName">
                                {{item.codingName}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="风险识别维度：">
                        <!--    <Input type="text" v-model="form1.rikDiscernName"/>-->
                        <Select v-model="form1.rikDiscernName">
                            <Option v-for="item in rikDiscernList" :value="item.codingCodeId" :label="item.codingName">
                                {{item.codingName}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>

                <Col span="8">
                    <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form" style="padding-top: 10px">
                <Col span="8">
                    <FormItem label="风险类别：">
                        <Select filterable v-model="form1.riskType"
                                :label-in-value="true">
                            <Option v-for="item in riskTypeArr" :value="item.codingCodeId" :label="item.codingName">
                                {{item.codingName}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>

                <Col span="8">
                    <FormItem label="风险识别维度：">
                        <!--  <Input type="text" v-model="form1.rikDiscernName"/>-->
                        <Select v-model="form1.rikDiscernName">
                            <Option v-for="item in rikDiscernList" :value="item.codingCodeId" :label="item.codingName">
                                {{item.codingName}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="风险等级：">
                        <!-- <Input type="text" v-model="form1.rikRankId"/>-->
                        <Select v-model="rikRanks" multiple style="width:100%">
                            <Option v-for="item in rikRankList" :value="item" :key="item">{{ item }}</Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">

                <Col span="8">
                    <FormItem label="一级风险单元：">
                        <Input type="text" v-model="form1.riskUnit"/>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="二级风险单元：">
                        <Input type="text" v-model="form1.riskUnit2"/>
                    </FormItem>
                </Col>

                <Col span="8">
                    <FormItem label="三级风险单元：">
                        <Input type="text" v-model="form1.riskUnit3"/>
                    </FormItem>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">

                <Col span="8">
                    <FormItem label="四级风险单元：">
                        <Input type="text" v-model="form1.riskUnit4"/>
                    </FormItem>
                </Col>
                <Col span="8" offset="8">
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' :loading="loading" size="small" :height="tableHeight" class="table" no-data-text="没有查询到相关数据!"
               highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
                      style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>

        <Modal :transfer=false v-model="model1" :width=1000
               :title="add?'作业流程风险预置新增':'作业流程风险预置修改'"
               @on-cancel="onCancel">
            <Form ref='InputData' :model="InputData" :rules="ruleCustom" label-position="top">
                <Row style="line-height: 25px;">
                    <Col span='2'>
                        <b>基础信息</b>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='一级风险单元：' prop="riskUnit">
                            <!--<Input v-model="InputData.saRiskInfo.riskUnit"/>-->
                            <cascaderDom ref="riskUnit" @setOrgInfo="setRiskUnit" @setOrgname="setRiskUnitName"
                                         :currentOrgId="InputData.saRiskInfo.riskUnit"
                                         :currentOrgName="InputData.saRiskInfo.riskUnitName"
                                         :orgTree="true"></cascaderDom>

                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='二级风险单元：' prop="riskUnit2">
                            <Input v-model="InputData.saRiskInfo.riskUnit2"/>
<!--                            <Select filterable v-model="InputData.saRiskInfo.riskUnit2"
                                    :placeholder="InputData.saRiskInfo.riskUnit==null?'一级风险单元不能为空':'请选择'"
                                    @on-open-change="openChange"
                                    allow-create @on-create="riskUnit2Add">
                                <Option v-for="item in riskUnit2s" :value="item" :label="item">
                                    {{item}}
                                </Option>
                            </Select>-->
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='三级风险单元：' prop="riskUnit3">
                            <Input v-model="InputData.saRiskInfo.riskUnit3"/>
<!--                            <Select filterable v-model="InputData.saRiskInfo.riskUnit3"
                                    :placeholder="InputData.saRiskInfo.riskUnit2==null?'二级风险单元不能为空':'请选择'"
                                    @on-open-change="openChange"
                                    allow-create @on-create="riskUnit3Add">
                                <Option v-for="item in riskUnit3s" :value="item" :label="item">
                                    {{item}}
                                </Option>
                            </Select>-->
                        </FormItem>
                    </Col>
                    <Col span='6' offset="3">
                        <FormItem label='四级风险单元：' prop="riskUnit4">
                            <Input v-model="InputData.saRiskInfo.riskUnit4"/>
<!--                            <Select filterable v-model="InputData.saRiskInfo.riskUnit4"
                                    :placeholder="InputData.saRiskInfo.riskUnit3==null?'三级风险单元不能为空':'请选择'"
                                    @on-open-change="openChange"
                                    allow-create @on-create="riskUnit4Add">
                                <Option v-for="item in riskUnit4s" :value="item" :label="item">{{item}}</Option>
                            </Select>-->
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='作业内容：' prop="workContent">
                            <Input v-model="InputData.saRiskInfo.workContent"/>
<!--                            <Select filterable v-model="InputData.saRiskInfo.workContent"
                                    :placeholder="InputData.saRiskInfo.riskUnit4==null?'四级风险单元不能为空':'请选择'"
                                    @on-open-change="openChange"
                                    allow-create @on-create="workContentAdd">
                                <Option v-for="item in workContents" :value="item" :label="item">{{item}}</Option>
                            </Select>-->
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='风险类别：' prop="riskType">
                            <Select filterable v-model="InputData.saRiskInfo.riskType" @on-change="changeSelect"
                                    :label-in-value="true">
                                <Option v-for="item in riskTypeArr" :value="item.codingCodeId" :label="item.codingName">
                                    {{item.codingName}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='13' offset="3">
                        <FormItem label='风险描述：' prop="riskDesc">
                            <Input v-model="InputData.saRiskInfo.riskDesc" type="textarea"
                                   :autosize="{minRows:2,maxRows:5}"/>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='风险识别维度：' prop="rikDiscernName">
                            <!--  <Input v-model="InputData.saRiskInfo.rikDiscernName"/>-->
                            <Select filterable v-model="InputData.saRiskInfo.rikDiscernId" @on-change="rikDiscernChange"
                                    :label-in-value="true">
                                <Option v-for="item in rikDiscernList" :value="item.codingCodeId"
                                        :label="item.codingName">
                                    {{item.codingName}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <hr style="margin-top: 10px;color: #dcdcdc"/>
                <Row style="line-height: 25px;margin-top: 10px">
                    <Col span='2'>
                        <b>风险评价</b>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='历史发生概率Q1：' prop="q1">
                            <Select v-model="InputData.q1">
                                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                                    <span> {{item.id}}</span>
                                    <span style="float:right;color:#ccc"> {{item.q1Name }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='风险承受能力Q2：' prop="q2">
                            <Select v-model="InputData.q2">
                                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                                    <span> {{item.id}}</span>
                                    <span style="float:right;color:#ccc"> {{item.q2Name }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='死亡损失M1：' prop="m1">
                            <Select v-model="InputData.m1">
                                <Option v-for="item in q1List" v-show="item.m1Name!=null" :value="item.id"
                                        :label="item.id">
                                    <span> {{item.id}}</span>
                                    <span style="float:right;color:#ccc"> {{item.m1Name }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="3">
                        <FormItem label='重伤损失M2：' prop="m2">
                            <Select v-model="InputData.m2">
                                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                                    <span> {{item.id}}</span>
                                    <span style="float:right;color:#ccc"> {{item.m2Name }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='经济损失E1：' prop="e1">
                            <Select v-model="InputData.e1">
                                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                                    <span> {{item.id}}</span>
                                    <span style="float:right;color:#ccc"> {{item.e1Name }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='周边敏感目标影响人数S1：' prop="s1">
                            <Select v-model="InputData.s1">
                                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                                    <span> {{item.id}}</span>
                                    <span style="float:right;color:#ccc"> {{item.s1Name }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row style="line-height: 25px">
                    <Col span='6' offset="3">
                        <FormItem label='社会关注度S2：' prop="s2">
                            <Select v-model="InputData.s2">
                                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                                    <span> {{item.id}}</span>
                                    <span style="float:right;color:#ccc"> {{item.s2Name }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row style="line-height: 25px;margin-top: 10px">
                    <Col span='6' offset="3">
                        <span>可能性计算：{{passibleCal}}</span>
                    </Col>
                    <Col span='6' offset="1">
                        <span>严重性计算：{{InputData.severityCal}}</span>
                    </Col>
                    <Col span='6' offset="1">
                        <span>风险等级R：{{InputData.rikRankName}}</span>
                    </Col>
                </Row>
                <Row style="line-height: 25px;margin-top: 10px">
                    <Col span='6' offset="3">
                        <span>可能性值：{{passibleCal}}</span>
                    </Col>
                    <Col span='6' offset="1">
                        <span>严重性值：{{InputData.severityVal}}</span>
                    </Col>
                    <Col span='6' offset="1">
                        <span>风险警示色：
                            <span v-if="InputData.rikColor=='红'" style="color: red">{{InputData.rikColor}}</span>
                            <span v-else-if="InputData.rikColor=='橙'"
                                  style="color: orange">{{InputData.rikColor}}</span>
                            <span v-else-if="InputData.rikColor=='黄'"
                                  style="color: #FDD835">{{InputData.rikColor}}</span>
                            <span v-else-if="InputData.rikColor=='蓝'" style="color: blue">{{InputData.rikColor}}</span>
                            <span v-else style="color: white">{{InputData.rikColor}}</span>
                        </span>
                    </Col>
                </Row>
                <hr style="margin-top: 10px;color: #dcdcdc"/>
                <Row style="line-height: 25px;margin-top: 10px">
                    <Col span='2'>
                        <b>风险管控</b>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='风险防范措施(技术、管理、教育)：' prop="manageMeasure">
                            <Input v-model="InputData.saRiskManage.manageMeasure"/>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='应急措施(救治、处置)：' prop="emerMearsure">
                            <Input v-model="InputData.saRiskManage.emerMearsure"/>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='责任部门：' prop="dutyOrgName"><!-- dutyOrgId -->
                            <Input v-model="InputData.saRiskManage.dutyOrgName"/>
                            <!--<cascaderDom ref="childOrg" @setOrgInfo="setOrgId" @setOrgname="setOrgName"
                                         :currentOrgId="InputData.saRiskManage.dutyOrgId"
                                         :currentOrgName="InputData.saRiskManage.dutyOrgName"
                                         :orgTree="true"></cascaderDom>-->
                        </FormItem>
                    </Col>
                    <Col span='6' offset="3">
                        <FormItem label='责任人：' prop="dutyPersonName"><!--dutyPersonId-->
                          <!--  <cascaderDom ref="childUser1" @setOrgInfo="setUserId" @setOrgname="setUserName"
                                         :currentOrgId="InputData.saRiskManage.dutyPersonId"
                                         :currentOrgName="InputData.saRiskManage.dutyPersonName">
                            </cascaderDom>-->
                            <Input v-model="InputData.saRiskManage.dutyPersonName"/>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='关注层面：' prop="focusAspectId">
                            <Select v-model="InputData.saRiskManage.focusAspectId" @on-change="focusAspectChange"
                                    :label-in-value="true">
                                <Option v-for="item in focusAspectList" :value="item.codingCodeId"
                                        :label="item.codingName">
                                    {{item.codingName}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='关注周期：' prop="focusCycleId">
                            <Select v-model="InputData.saRiskManage.focusCycleId" @on-change="focusCycleChange"
                                    :label-in-value="true">
                                <Option v-for="item in focusCycleList" :value="item.codingCodeId"
                                        :label="item.codingName">
                                    {{item.codingName}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="3">
                        <FormItem label='审核人：' prop="checker">
                            <!--<Input v-model="InputData.saRiskAssess.checker"/>-->
                           <!-- <cascaderDom ref="childUser" @setOrgInfo="setUserId1" @setOrgname="setUserName1"
                                         :currentOrgId="InputData.saRiskAssess.checker"
                                         :currentOrgName="InputData.saRiskAssess.checkerName">
                            </cascaderDom>-->
                            <Select
                                    v-model="InputData.saRiskAssess.checker"
                                    filterable
                                    :remote-method="remoteMethod1"
                                    :loading="loading1">
                                <Option v-for="(option, index) in options1" :value="option.userId"
                                        :label="option.userName" :key="index">
                                    <span>{{option.userName}}</span>
                                    <span style="float:right;color:#ccc">{{option.orgInfo.orgName}}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='录入人：'>
                            {{InputData.saRiskManage.recorder}}
                        </FormItem>
                    </Col>
                    <Col span='6' offset="1">
                        <FormItem label='录入时间：'>
                            {{InputData.saRiskManage.recordeTime}}
                        </FormItem>
                    </Col>
                </Row>
                <!-- <Row type="flex" justify="space-around" class="code-row-bg">
                     <Col span="23">
                         <FormItem>
                             <Button class='ivu-btn-save' :loading="buttonLoading" @click="submit('InputData')">确定</Button>
                             <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
                         </FormItem>
                     </Col>
                 </Row>-->
            </Form>
            <div slot="footer">
                <Button class='ivu-btn-save' :loading="buttonLoading" @click="submit('InputData')">确定</Button>
                <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
            </div>
        </Modal>

        <Modal :transfer=false v-model="model3" :width=1000 title="作业流程风险">
            <Form :model="InputData" label-position="top">
                <workProcessRiskApproval ref="workProcessRiskApproval"
                                         :InputData="InputData"></workProcessRiskApproval>
                <!--<Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="23">
                        <FormItem>
                            <Button class='ivu-btn-save' @click="model3=false">关闭</Button>
                        </FormItem>
                    </Col>
                </Row>-->
            </Form>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="model3=false">关闭</Button>
            </div>
        </Modal>

    </Layout>
</template>

<script>
import {Api} from '../../../../api/index.js'
import {sessionStorage} from '../../../../common/cacheUtils.js';
import cascaderDom from '../../../../components/cascader-dom.vue';
import workProcessRiskApproval from '../riskApproval/workProcessRiskApproval.vue'

export default {
        // props: ['riskUnitsAll'],
        components: {cascaderDom, workProcessRiskApproval},
        name: "workProcessRiskPreset",//作业流程风险预置
        data() {
            return {
                options1:[],
                rikRankList: ["重大", "较大", "一般", "低"],
                rikRanks: [],
                focusCycleList: [],
                focusAspectList: [],
                tableHeight: '',
                loading: false,
                form1: {
                    hazardFactor: '',
                    rikRankId: '',
                },
                rootOrgId: sessionStorage('userId').getObject('userId').orgInfo.orgId,
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                switchFlag: false,
                dataTable: [],
                ruleCustom: {
                    riskUnit: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.riskUnit == null || this.InputData.saRiskInfo.riskUnit == '' || this.InputData.saRiskInfo.riskUnit == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    riskUnit2: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.riskUnit2 == null || this.InputData.saRiskInfo.riskUnit2 == '' || this.InputData.saRiskInfo.riskUnit2 == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    riskUnit3: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.riskUnit3 == null || this.InputData.saRiskInfo.riskUnit3 == '' || this.InputData.saRiskInfo.riskUnit3 == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    riskUnit4: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.riskUnit4 == null || this.InputData.saRiskInfo.riskUnit4 == '' || this.InputData.saRiskInfo.riskUnit4 == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    workContent: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.workContent == null || this.InputData.saRiskInfo.workContent == '' || this.InputData.saRiskInfo.workContent == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    riskType: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.riskType == null || this.InputData.saRiskInfo.riskType == '' || this.InputData.saRiskInfo.riskType == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    rikDiscernName: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.rikDiscernName == null || this.InputData.saRiskInfo.rikDiscernName == '' || this.InputData.saRiskInfo.rikDiscernName == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    riskDesc: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskInfo.riskDesc == null || this.InputData.saRiskInfo.riskDesc == '' || this.InputData.saRiskInfo.riskDesc == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],

                    q1: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    q2: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    m1: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    m2: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    e1: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    s1: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    s2: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],

                    manageMeasure: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskManage.manageMeasure == null || this.InputData.saRiskManage.manageMeasure == '' || this.InputData.saRiskManage.manageMeasure == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    emerMearsure: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskManage.emerMearsure == null || this.InputData.saRiskManage.emerMearsure == '' || this.InputData.saRiskManage.emerMearsure == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    dutyOrgName: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskManage.dutyOrgName == null || this.InputData.saRiskManage.dutyOrgName == '' || this.InputData.saRiskManage.dutyOrgName == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    dutyPersonName: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskManage.dutyOrgName == null || this.InputData.saRiskManage.dutyOrgName == '' || this.InputData.saRiskManage.dutyOrgName == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    focusAspectId: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskManage.focusAspectId == null || this.InputData.saRiskManage.focusAspectId == '' || this.InputData.saRiskManage.focusAspectId == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    focusCycleId: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskManage.focusCycleId == null || this.InputData.saRiskManage.focusCycleId == '' || this.InputData.saRiskManage.focusCycleId == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],

                    checker: [{
                        validator: (rule, value, callback) => {
                            if (this.InputData.saRiskAssess.checker == null || this.InputData.saRiskAssess.checker == '' || this.InputData.saRiskAssess.checker == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                },
                columns1: [
                    {
                        title: "序号",
                        width: 80,
                        align: "center",
                        fixed: 'left',
                        render: (h, params) => {
                            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    {
                        width: 200,
                        minWidth: 150,
                        title: '一级风险单元',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.saRiskInfo.riskUnitName)
                        }
                    },
                    {
                        width: 200,
                        minWidth: 150,
                        title: '二级风险单元',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.saRiskInfo.riskUnit2)
                        }
                    },
                    {
                        width: 200,
                        minWidth: 150,
                        title: '三级风险单元',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.saRiskInfo.riskUnit3)
                        }
                    }, {
                        width: 200,
                        minWidth: 150,
                        title: '四级风险单元',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.saRiskInfo.riskUnit4)
                        }
                    }, {
                        width: 200,
                        minWidth: 150,
                        title: '作业内容',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.saRiskInfo.workContent)
                        }
                    },
                    {
                        width: 150,
                        title: '风险类别',
                        align: 'center',
                        key: 'riskTypeName',
                        render: (h, params) => {
                            return h('span', params.row.saRiskInfo.riskTypeName)
                        }
                    },
                    {
                        width: 150,
                        title: '风险识别维度',
                        align: 'center',
                        key: 'rikDiscernName',
                        render: (h, params) => {
                            return h('span', params.row.saRiskInfo.rikDiscernName)
                        }
                    },
                    {
                        width: 150,
                        title: '风险等级',
                        align: 'center',
                        key: 'rikRankName',
                    },
                    {
                        width: 150,
                        title: '风险警示色',
                        align: 'center',
                        key: 'rikColor',
                        /* render: (h, params) => {
                             // 需要延迟处理，否则颜色无法赋值
                             setTimeout(() => {
                                 let dom = document.getElementsByClassName(`${params.row.cellClassName.rikColor}`)
                                 dom[0].style.backgroundColor = `${params.row.cellClassName.rikColor}`
                             }, 100)
                             return h('div', {
                                 style: {
                                     color: 'black'
                                 }
                             }, params.row.rikColor)
                         }*/
                    },
                    {
                        width: 150,
                        title: '风险防范措施',
                        align: 'center',
                        key: 'manageMeasure',
                        ellipsis:'true',
                        render: (h, params) => {
                            return h('span', params.row.saRiskManage.manageMeasure)
                        }
                    },
                    {
                        width: 150,
                        title: '应急措施',
                        align: 'center',
                        key: 'emerMearsure',
                        ellipsis:'true',
                        render: (h, params) => {
                            return h('span', params.row.saRiskManage.emerMearsure)
                        }
                    },
                    {
                        width: 150,
                        title: '责任部门',
                        align: 'center',
                        key: 'dutyOrgName',
                        render: (h, params) => {
                            return h('span', params.row.saRiskManage.dutyOrgName)
                        }
                    },
                    {
                        width: 150,
                        title: '责任人',
                        align: 'center',
                        key: 'dutyPersonName',
                        render: (h, params) => {
                            return h('span', params.row.saRiskManage.dutyPersonName)
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                    },
                                    on: {
                                        click: () => {
                                            this.InputData = params.row;
                                            let recordeTime = new Date(params.row.saRiskManage.recordeTime)
                                            this.InputData.saRiskManage.recordeTime = recordeTime.getFullYear() + '-' + (recordeTime.getMonth() + 1) + '-' + recordeTime.getDate()
                                            this.model3 = true;
                                            this.query1()
                                        }
                                    }
                                }, '详情'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                    },
                                    on: {
                                        click: () => {
                                            this.InputData = params.row;
                                            let recordeTime = new Date(params.row.saRiskManage.recordeTime);
                                            this.options1 = [];
                                            this.options1.push({userId: this.InputData.saRiskAssess.checker, userName: this.InputData.saRiskAssess.checkerName, orgInfo: {orgName: ''}});
                                            this.InputData.saRiskManage.recordeTime = recordeTime.getFullYear() + '-' + (recordeTime.getMonth() + 1) + '-' + recordeTime.getDate()
                                            this.model1 = true;
                                            this.add = false;
                                        }
                                    }
                                }, '修改'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: 'red',
                                    },
                                    on: {
                                        click: () => {
                                            this.deleteData(params.row);
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                add: false,
                model1: false,
                model3: false,
                InputData: {
                    saRiskInfo: {},
                    saRiskAssess: {},
                    saRiskManage: {}
                },
                q1List: [
                    {
                        id: 1,
                        q1Name: '基本不可能(过去从未发生)',
                        q2Name: '承受力很强',
                        m1Name: '小(0人)',
                        m2Name: '很小(小于等于1人)',
                        e1Name: '很小(小于10万元)',
                        s1Name: '很小(影响小于10人)',
                        s2Name: '很小(本区关注1(含)天至7天或本市关注1天内)',
                    },
                    {
                        id: 2,
                        q1Name: '较不可能(过去10年以上发生1次)',
                        q2Name: '承受力强',
                        m2Name: '小(2人)',
                        e1Name: '小(10万元至50万元)',
                        s1Name: '小(影响在10至99人之间)',
                        s2Name: '小(本区关注7(含)天至30天或本市关注1(含)天至7天或国内关注1天内)',
                    },
                    {
                        id: 3,
                        q1Name: '可能(过去10年发生1次)',
                        q2Name: '承受力一般',
                        m1Name: '一般(1人)',
                        m2Name: '一般(3至5人)',
                        e1Name: '一般(50万元至100万元)',
                        s1Name: '一般(影响在100至499人之间)',
                        s2Name: '一般(本区关注30(含)天以上或本市关注7(含)天至30天或国内关注1(含)天至7天或国际关注1天内)',
                    },
                    {
                        id: 4,
                        q1Name: '较可能(过去5年发生1次)',
                        q2Name: '承受力弱',
                        m1Name: '大(2人)',
                        m2Name: '大(6至8人)',
                        e1Name: '大(100万元至500万元)',
                        s1Name: '大(影响在500至999人之间)',
                        s2Name: '大(本市关注30(含)天以上或国内关注7(含)天至30天或国际关注1(含)天至7天)',
                    },
                    {
                        id: 5,
                        q1Name: '很可能(过去2年发生1次以上)',
                        q2Name: '承受力很弱',
                        m1Name: '很大(大于等于3人)',
                        m2Name: '很大(大于等于9人)',
                        e1Name: '很大(大于等于500万元)',
                        s1Name: '很大(影响大于等于1000人)',
                        s2Name: '很大(国内关注30(含)天以上或国际关注7(含)天以上)',
                    }
                ],
                riskTypeArr: [],
                buttonLoading: false,
                riskUnits: [],
                riskUnit2s: [],
                riskUnit3s: [],
                riskUnit4s: [],
                workContents: [],
                rikDiscernList: [],
                loading1:false
            }
        },
        computed: {
            passibleCal: function () {
                let r5 = 0 //可能性计算
                let s5 = 0 //严重性计算
                let rikRan = ' '
                let rikColor = ' '
                if (this.InputData.q1 > 0 && this.InputData.q2 > 0) {
                    r5 = Math.ceil(this.NumberAdd(this.InputData.q1, this.InputData.q2) / 2)
                }
                if (this.InputData.m1 > 0 && this.InputData.m2 > 0 && this.InputData.e1 > 0 && this.InputData.s1 > 0 && this.InputData.s2 > 0) {
                    s5 = Math.ceil((this.InputData.m1 + this.InputData.m2 + this.InputData.e1 + this.InputData.s1 + this.InputData.s2) / 5)
                }
                this.InputData.severityCal = s5 > 0 ? s5 : ' ';
                this.InputData.severityVal = s5 > 0 ? s5 : ' ';

                this.InputData.passibleCal = r5 > 0 ? r5 : ' ';
                this.InputData.passibleVal = r5 > 0 ? r5 : ' ';
                if (s5 == 0 || r5 == 0) {
                    rikRan = ' '
                } else if ((r5 > 2 && s5 == 5) || (r5 == 5 && s5 == 4)) {
                    rikRan = '重大'
                } else if ((r5 == 2 && s5 == 5) || ((r5 == 3 || r5 == 4) && s5 == 4) || (r5 > 3 && s5 == 3) || (s5 == 2 && r5 == 5)) {
                    rikRan = '较大'
                } else if ((r5 == 1 && s5 > 3) || ((s5 == 3 || s5 == 4) && r5 == 2) || ((s5 == 2 || s5 == 3) && r5 == 3) || (s5 == 2 && r5 == 4) || (s5 == 1 && r5 > 3)) {
                    rikRan = '一般'
                } else {
                    rikRan = '低'
                }
                rikColor = rikRan == '重大' ? '红' : rikRan == '较大' ? '橙' : rikRan == '一般' ? '黄' : rikRan == '低' ? '蓝' : ' '
                this.InputData.rikRankName = rikRan;
                this.InputData.rikColor = rikColor
                this.InputData.saRiskAssess.rikColor = rikColor
                return this.InputData.passibleCal;
            }
        },
        watch: {
            "model1": function (qw, er) {
                if (qw && this.model1) {
                    setTimeout(() => {
                        this.$refs.riskUnit.setCurrentOrg();
                        this.$refs.childOrg.setCurrentOrg();
                        this.$refs.childUser.setCurrentOrg();
                        this.$refs.childUser1.setCurrentOrg();
                    }, 100);
                } else {
                    this.$refs.riskUnit.resetCurrentOrg();
                    this.$refs.childOrg.resetCurrentOrg();
                    this.$refs.childUser.resetCurrentOrg();
                    this.$refs.childUser1.resetCurrentOrg();
                }
                this.openChange()
            },
        },
        mounted() {
            this.tableHeight = window.innerHeight - 325
            //this.$refs.table.$el.offsetTop - 220;
            this.query()
        },
        methods: {
            remoteMethod1(query) {
                if (query !== '') {
                    clearTimeout(this.remoteMethod1.timer);
                    this.remoteMethod1.timer = setTimeout(() => {
                        this.options1.splice(0, this.options1.length);
                        this.loading1 = true;
                        let data = {
                            userName: query,
                            orgId: sessionStorage('userId').getObject('userId').orgInfo.parentId
                        };
                        this.$http.get(Api.queryUserByUserName, {params: data}).then((res) => {
                            this.loading1 = false;
                            res.data.data.forEach(item => {
                                this.options1.push(item);
                            })

                        }).catch(e => {
                            this.loading1 = false;
                        })
                    }, 200);
                } else {
                    this.options1 = [];
                }
            },
            focusAspectChange(e) {
                this.InputData.saRiskManage.focusAspectId = e.value;
                this.InputData.saRiskManage.focusAspect = e.label;

            },
            focusCycleChange(e) {
                this.InputData.saRiskManage.focusCycleId = e.value;
                this.InputData.saRiskManage.focusCycle = e.label;

            },
            query1() {
                let url = Api.riskUnitsList + '/' + sessionStorage('userId').getObject('userId').orgInfo.orgId
                this.$http.get(url).then((res) => {
                    this.riskUnitsAll = res.data.data;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            openChange() {
                this.riskUnitsAll.forEach(item => {
                    this.riskUnits.push(item.riskUnit)
                    this.riskUnits = [...new Set(this.riskUnits)].filter(function (s) {
                        return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
                    })
                    if (item.riskUnit == this.InputData.saRiskInfo.riskUnit) {
                        this.riskUnit2s.push(item.riskUnit2)
                        this.riskUnit2s = [...new Set(this.riskUnit2s)].filter(function (s) {
                            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
                        })
                    }
                    if (item.riskUnit2 == this.InputData.saRiskInfo.riskUnit2) {
                        this.riskUnit3s.push(item.riskUnit3)
                        this.riskUnit3s = [...new Set(this.riskUnit3s)].filter(function (s) {
                            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
                        })
                    }
                    if (item.riskUnit3 == this.InputData.saRiskInfo.riskUnit3) {
                        this.riskUnit4s.push(item.riskUnit4)
                        this.riskUnit4s = [...new Set(this.riskUnit4s)].filter(function (s) {
                            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
                        })
                    }
                    if (item.riskUnit4 == this.InputData.saRiskInfo.riskUnit4) {
                        this.workContents.push(item.workContent)
                        this.workContents = [...new Set(this.workContents)].filter(function (s) {
                            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
                        })
                    }
                })
            },
            riskUnitAdd(val) {
                this.riskUnits.push(val)
                this.riskUnit2s = []
            },
            riskUnit2Add(val) {
                this.riskUnit2s.push(val);
                this.riskUnit3s = []
            },
            setRiskUnit(data) {
                this.InputData.saRiskInfo.riskUnit = data[data.length - 1];
            },
            setRiskUnitName(data) {
                this.InputData.saRiskInfo.riskUnitName = data;
            },
            riskUnit3Add(val) {
                this.riskUnit3s.push(val);
                this.riskUnit4s = []
            },
            riskUnit4Add(val) {
                this.riskUnit4s.push(val);
                this.workContents = []
            },
            workContentAdd(val) {
                this.workContents.push(val);
            },

            changeSelect(appStatus) {
                this.InputData.saRiskInfo.riskType = appStatus.value;
                this.InputData.saRiskInfo.riskTypeName = appStatus.label;
            },

            setOrgId(data) {
                this.InputData.saRiskManage.dutyOrgId = data[data.length - 1];
            },
            setOrgName(data) {
                this.InputData.saRiskManage.dutyOrgName = data;
            },
            setUserName(data) {
                this.InputData.saRiskManage.dutyPersonName = data;
            },
            setUserId(data) {
                this.InputData.saRiskManage.dutyPersonId = data[data.length - 1];
            },
            setUserName1(data) {
                this.InputData.saRiskAssess.checkerName = data;
            },
            setUserId1(data) {
                this.InputData.saRiskAssess.checker = data[data.length - 1];
            },
            rikDiscernChange(appStatus) {
                this.InputData.saRiskInfo.rikDiscernId = appStatus.value;
                this.InputData.saRiskInfo.rikDiscernName = appStatus.label;
            },
            onCancel() {
                this.InputData = {
                    saRiskInfo: {},
                    saRiskAssess: {},
                    saRiskManage: {}
                }
                this.model1 = false
                this.query()
            },
            submit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.buttonLoading = true
                        this.InputData.saRiskAssess.preset = '0'//0是预置  1不是预置
                        this.InputData.saRiskManage.recordeTime = new Date(this.InputData.saRiskManage.recordeTime)
                        let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
                        let userId = sessionStorage('userId').getObject('userId').userId
                        let url = ''
                        if (this.add) {
                            url = Api.workProcessRiskAdd
                            this.InputData.bsflag = '0'
                            this.InputData.createOrgId = orgId
                            this.InputData.createUserId = userId
                            this.InputData.saRiskInfo.createOrgId = orgId
                            this.InputData.saRiskInfo.createUserId = userId
                            this.InputData.saRiskAssess.createOrgId = orgId
                            this.InputData.saRiskAssess.createUserId = userId
                            this.InputData.saRiskManage.createOrgId = orgId
                            this.InputData.saRiskManage.createUserId = userId
                            this.$http.post(url, this.InputData).then((res) => {
                                this.$Message.success('成功');
                                this.query()
                                this.buttonLoading = false
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                            this.model1 = false
                        } else {
                            url = Api.workProcessRiskUpdate;
                            this.InputData.updateUserId = userId
                            this.InputData.updateOrgId = orgId
                            this.InputData.saRiskInfo.updateUserId = userId
                            this.InputData.saRiskInfo.updateOrgId = orgId
                            this.InputData.saRiskAssess.updateUserId = userId
                            this.InputData.saRiskAssess.updateOrgId = orgId
                            this.InputData.saRiskManage.updateUserId = userId
                            this.InputData.saRiskManage.updateOrgId = orgId
                            this.$http.post(url, this.InputData).then((res) => {
                                this.$Message.success('成功');
                                this.buttonLoading = false
                                this.query()
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                            this.model1 = false
                        }
                    } else {
                        this.$Message.error('失败!');
                    }
                })

            },

            deleteData(row) {
                this.$Modal.confirm({
                        title: '提示',
                        content: '<p>确认删除此行数据？</p>',
                        onOk: () => {
                            let url = Api.workProcessRiskDelete + '/' + row.bizId
                            this.$http.delete(url).then((res) => {
                                this.$Message.success('删除成功');
                                this.query()
                            }).catch(e => {
                                this.$Message.error("删除失败")
                            })
                        },
                    onCancel: () => {
                    }
                });
            },
            addInfo() {
                this.add = true;
                this.riskUnits = [];
                this.riskUnit2s = [];
                this.riskUnit3s = [];
                this.riskUnit4s = [];
                this.InputData = {
                    saRiskInfo: {},
                    saRiskAssess: {},
                    saRiskManage: {
                        recorder: sessionStorage('userId').getObject('userId').userName,
                        recordeTime: new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate()
                    }
                };
                this.model1 = true;
            },
            query() {
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize
                }
                this.form1.orgId = sessionStorage('userId').getObject('userId').companyId
                this.form1.preset = '0'
                this.form1.rikRankId = "";
                for (let i = 0; i < this.rikRanks.length; i++) {
                    this.form1.rikRankId += this.rikRanks[i] + ",";

                }
                data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
                let url = Api.workProcessRiskList
                this.loading = true;
                this.$http.get(url, {params: data}).then((res) => {
                    console.log(res.data);
                    res.data.data.data.forEach(item => {
                        const sty = item.rikColor == '红' ? 'table-info-cell-red' : item.rikColor == '橙' ? 'table-info-cell-orage' : item.rikColor == '黄' ? 'table-info-cell-yellow' : item.rikColor == '蓝' ? 'table-info-cell-blue' : ''
                        item.cellClassName = {rikColor: sty}
                    })
                    this.dataTable = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    this.loading = false;

                }).catch(e => {
                    this.$Message.error("数据获取失败")
                    this.loading = false;
                })
                this.query1()

                let _this = this
                this.gDic(Api.queryCodeDetailBySortId + "/risk-10007", function (result) {
                    _this.riskTypeArr = result;
                });
                this.gDic(Api.queryCodeDetailBySortId + "/risk-10011", function (result) {
                    _this.rikDiscernList = result;
                });
                this.gDic(Api.queryCodeDetailBySortId + "/risk-10014", function (result) {
                    _this.focusCycleList = result;
                });
                this.gDic(Api.queryCodeDetailBySortId + "/risk-10015", function (result) {
                    _this.focusAspectList = result;
                });
            },
            reset() {
                this.form1 = {}
                this.rikRanks = [];
                this.pagedata.currentPage=1
                this.query()
            },
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            switchQuery(flag) {
                this.switchFlag = flag;
                if (!this.switchFlag) {
                    this.tableHeight = this.tableHeight + 88;
                } else {
                    this.tableHeight = this.tableHeight - 88;
                }
            },
        }
    }
</script>

<style scoped>
    @import '../../../../index.css';
</style>
